/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import MouseSensorDriver.Calibrator;
import MouseSensorDriver.MouseSensorHost;
import MouseSensorDriver.MouseSensorListener;
import adc_lcard.ADCE140Driver;
import dynamixel.Actuator;
import dynamixel.HostActuator;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.Timer;
import jssc.SerialPortException;
import jssc.SerialPortList;

/**
 *
 * @author Asko
 */
public class StartFrame extends javax.swing.JFrame {

    static final int ADC_MAX = 65530;
    static final int ADC_MIN = 1;
    boolean turnON = false;
    StartFrame sf;
    MouseSensorHost mouseHost;
    HostActuator actuatorHost;
    Actuator posActuator;
    Actuator axisActuator;
    String[] portList = SerialPortList.getPortNames();
    DefaultComboBoxModel<String> dynamixelModel = new DefaultComboBoxModel<>();
    DefaultComboBoxModel<String> sensorModel = new DefaultComboBoxModel<>();
    Calibrator calib = new Calibrator();
    double curPos = 0;
    double axisCurPos = 0;
    double mouseCurPos = 0;
    double mouseAxisCurPos = 0;
    static int channelPos = Calibrator.ADC_CHANELL_3;
    static int channelAxisPos = Calibrator.ADC_CHANELL_2;
    int updateCnt = 0;
    Timer timer = new Timer(10, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            sf.setAxisCurPos(calib.getData(channelAxisPos, ADCE140Driver
                    .getData(channelAxisPos)));
            sf.setCurPos(calib.getData(channelPos, ADCE140Driver.getData(channelPos)));
            updateCnt++;
            if (updateCnt >= 10) {
                posTF.setText("" + Math.round(sf.getCurPos()));
                axisposTF.setText("" + Math.round(sf.getAxisCurPos()));
                jtf_mouse_pos.setText("" + Math.round(sf.getMouseCurPos()));
                jtf_axis_mouse_pos.setText("" + Math.round(sf.getMouseAxisCurPos()));

                updateCnt = 0;
            }
        }
    });

    /**
     * Creates new form StartFrame
     */
    public StartFrame() {
        for (int i = 0; i < portList.length; i++) {
            dynamixelModel.addElement(portList[i]);
            sensorModel.addElement(portList[i]);
        }
        if (!ADCE140Driver.init()) {
            System.out.println("Shit happened!");
        }
        curPos = calib.getData(channelPos, ADCE140Driver.getData(channelPos));
        axisCurPos = calib.getData(channelAxisPos, ADCE140Driver
                .getData(channelAxisPos));

        initComponents();

        mainPanel.setEnabled(false);
        for (Component comp : mainPanel.getComponents()) {
            comp.setEnabled(false);
        }
        this.setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        dBox = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        mBox = new javax.swing.JComboBox();
        initButton = new javax.swing.JButton();
        mainPanel = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jtf_axis_pos = new javax.swing.JTextField();
        jtf_goal_pos = new javax.swing.JTextField();
        axisExecButton = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        posTF = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        axisposTF = new javax.swing.JTextField();
        posExecButton = new javax.swing.JButton();
        TurnOn = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jtf_mouse_pos = new javax.swing.JTextField();
        jtf_axis_mouse_pos = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Dynamixel Port");

        dBox.setModel(dynamixelModel);

        jLabel2.setText("MouseSensor Port");

        mBox.setModel(sensorModel);

        initButton.setText("Init");
        initButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                initButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(dBox, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(39, 39, 39)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(mBox, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(34, 34, 34)
                .addComponent(initButton, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(dBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(mBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(initButton))
                .addGap(0, 1, Short.MAX_VALUE))
        );

        mainPanel.setEnabled(false);

        jLabel3.setText("Goal Position (grad)");

        jLabel4.setText("Goal Position (mm)");

        jtf_axis_pos.setText("0");

        jtf_goal_pos.setText("0");

        axisExecButton.setText("Execute");
        axisExecButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                axisExecButtonActionPerformed(evt);
            }
        });

        jLabel5.setText("Current position: ");

        posTF.setEditable(false);
        posTF.setText("0");

        jLabel6.setText("Current axis position: ");

        axisposTF.setEditable(false);
        axisposTF.setText("0");

        posExecButton.setText("Execute");
        posExecButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                posExecButtonActionPerformed(evt);
            }
        });

        TurnOn.setText("TurnOn");
        TurnOn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TurnOnActionPerformed(evt);
            }
        });

        jLabel7.setText("Current mouse position: ");

        jLabel8.setText("Current axis mouse position: ");

        jtf_mouse_pos.setEditable(false);
        jtf_mouse_pos.setText("0");

        jtf_axis_mouse_pos.setEditable(false);
        jtf_axis_mouse_pos.setText("0");

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                            .addComponent(jLabel5)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(posTF, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                            .addComponent(jLabel6)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(axisposTF, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(axisExecButton)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jtf_axis_pos, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(44, 44, 44)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(mainPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel4)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jtf_goal_pos, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(posExecButton))
                                .addGap(34, 34, 34)
                                .addComponent(TurnOn))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGap(90, 90, 90)
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel7)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jtf_mouse_pos, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel8)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jtf_axis_mouse_pos, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)))))))
                .addContainerGap(34, Short.MAX_VALUE))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jtf_axis_pos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtf_goal_pos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(axisExecButton)
                    .addComponent(posExecButton)
                    .addComponent(TurnOn))
                .addGap(26, 26, 26)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(posTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(axisposTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jtf_mouse_pos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(jtf_axis_mouse_pos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(70, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void initButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_initButtonActionPerformed
        initButton.setEnabled(false);
        try {
            mouseHost = new MouseSensorHost(portList[mBox.getSelectedIndex()], 38400);
            actuatorHost = new HostActuator(portList[dBox.getSelectedIndex()], 57142);
            posActuator = new Actuator(actuatorHost, 2);
            axisActuator = new Actuator(actuatorHost, 1);
            posActuator.setWheelMode(true);
            axisActuator.setWheelMode(true);
            mainPanel.setEnabled(true);
            for (Component comp : mainPanel.getComponents()) {
                comp.setEnabled(true);
            }
            mouseHost.addMouseSensorListener(new MouseSensorListener() {
                @Override
                public void measured(int dx1, int dy1, int dx2, int dy2, int dx3, int dy3) {
                    incMouseCurPos(calib.getData(Calibrator.MOUSE_SENSOR_Y, dy3));
                    incMouseAxisCurPos(calib.getData(Calibrator.MOUSE_SENSOR_X, dx3));
                }
            });
           /* calib.setCoefsOffset(channelPos, -calib.getData(channelPos,
                    ADCE140Driver.getData(channelPos)));
            calib.setCoefsOffset(channelAxisPos, -calib.getData(channelAxisPos,
                    ADCE140Driver.getData(channelAxisPos)));*/
            curPos = calib.getData(channelPos, ADCE140Driver.getData(channelPos));
            axisCurPos = calib.getData(channelAxisPos, ADCE140Driver
                    .getData(channelAxisPos));
            mouseCurPos = curPos;
            mouseAxisCurPos = axisCurPos;
            sf = this;

            timer.start();

        } catch (SerialPortException ex) {
            Logger.getLogger(StartFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_initButtonActionPerformed

    private void axisExecButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_axisExecButtonActionPerformed
        goToAxisPosition(Double.valueOf(jtf_axis_pos.getText()));
    }//GEN-LAST:event_axisExecButtonActionPerformed

    private void posExecButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_posExecButtonActionPerformed


        goToPosition(Double.valueOf(jtf_goal_pos.getText()));
    }//GEN-LAST:event_posExecButtonActionPerformed

    private void TurnOnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TurnOnActionPerformed
        turnON = !turnON;
        posActuator.turnOnLed(turnON);  // TODO add your handling code here:
    }//GEN-LAST:event_TurnOnActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(StartFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(StartFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(StartFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(StartFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new StartFrame().setVisible(true);
            }
        });
    }

    private void goToAxisPosition(double pos) {
        final double rs = pos;
        int sdata = calib.getSourceData(channelAxisPos, rs);
        if (sdata < ADC_MAX && sdata > ADC_MIN) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    boolean clockWise = false;
                    axisExecButton.setEnabled(false);

                    axisActuator.turnOnLed(true);
                    int speed = 20;
                    double axisCurpos = getAxisCurPos();
                    if ((rs < axisCurpos && calib.getCoefsProp(channelAxisPos) > 0)
                            || (rs > axisCurpos && calib.getCoefsProp(channelAxisPos) < 0)) {
                        clockWise = true;
                    }
                    axisActuator.setSpeed(speed, clockWise);
                    if (rs > axisCurpos) {
                        while (rs > getAxisCurPos()) {

                            try {
                                Thread.sleep(5);
                            } catch (InterruptedException ex) {
                                Logger.getLogger(StartFrame.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }

                    } else {

                        while (rs < getAxisCurPos()) {
                            try {
                                Thread.sleep(5);
                            } catch (InterruptedException ex) {
                                Logger.getLogger(StartFrame.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                    }
                    axisActuator.setSpeed(0, false);
                    axisActuator.turnOnLed(false);
                    axisExecButton.setEnabled(true);
                }
            }).start();
        }
    }

    private void goToPosition(double pos) {
        final double rs = pos;
        int sdata = calib.getSourceData(channelPos, rs);
        if (sdata < ADC_MAX && sdata > ADC_MIN) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    boolean clockWise = false;
                    posExecButton.setEnabled(false);
                    posActuator.turnOnLed(true);
                    double curPos = getCurPos();
                    int speed = 40;
                    if (((rs < curPos && calib.getCoefsProp(channelPos) > 0)
                            || (rs > curPos && calib.getCoefsProp(channelPos) < 0))) {
                        clockWise = true;
                    }
                    posActuator.setSpeed(speed, clockWise);
                    if (rs > curPos) {
                        while (rs > getCurPos()) {
                            //  System.out.println("rs > curPos " + rs + " " + getCurPos());
                            try {
                                Thread.sleep(20);
                            } catch (InterruptedException ex) {
                                Logger.getLogger(StartFrame.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                    } else {
                        while (rs < getCurPos()) {
                            //      System.out.println("rs < curPos " + rs + " " + getCurPos());
                            try {
                                Thread.sleep(20);
                            } catch (InterruptedException ex) {
                                Logger.getLogger(StartFrame.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                    }
                    posActuator.setSpeed(0, false);
                    posActuator.turnOnLed(false);
                    posExecButton.setEnabled(true);
                }
            }).start();
        }
    }

    public synchronized double getMouseCurPos() {
        return mouseCurPos;
    }

    public synchronized void incMouseCurPos(double dmouseCurPos) {
        this.mouseCurPos += dmouseCurPos;
    }

    public synchronized double getMouseAxisCurPos() {
        return mouseAxisCurPos;
    }

    public synchronized void incMouseAxisCurPos(double dmouseAxisCurPos) {
        this.mouseAxisCurPos += dmouseAxisCurPos;
    }

    public synchronized double getCurPos() {
        return curPos;
    }

    public synchronized void setCurPos(double curPos) {
        this.curPos = curPos;
    }

    public synchronized double getAxisCurPos() {
        return axisCurPos;
    }

    public synchronized void setAxisCurPos(double axisCurPos) {
        this.axisCurPos = axisCurPos;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton TurnOn;
    private javax.swing.JButton axisExecButton;
    private javax.swing.JTextField axisposTF;
    private javax.swing.JComboBox dBox;
    private javax.swing.JButton initButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jtf_axis_mouse_pos;
    private javax.swing.JTextField jtf_axis_pos;
    private javax.swing.JTextField jtf_goal_pos;
    private javax.swing.JTextField jtf_mouse_pos;
    private javax.swing.JComboBox mBox;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JButton posExecButton;
    private javax.swing.JTextField posTF;
    // End of variables declaration//GEN-END:variables
}
